/*
 * @Description: 文件上传
 * @Author: zhr
 */
import request from "@/utils/request";

export function uploadGeneralImg(data) {
  return request({
    url: "/file/api/v1/general/uploadImg",
    method: "post",
    headers: {
      "Content-Type": "multipart/form-data"
    },
    data
  });
}

export function uploadGeneralFile(data) {
  return request({
    url: "/file/api/v1/general/upload/attachment",
    method: "post",
    headers: {
      "Content-Type": "multipart/form-data"
    },
    data
  });
}

export function uploadSiteImg(data) {
  return request({
    url: "/file/api/v1/site/uploadImg",
    method: "post",
    headers: {
      "Content-Type": "multipart/form-data"
    },
    data
  });
}

export function uploadSiteFile(data) {
  return request({
    url: "/file/api/v1/site/upload/attachment",
    method: "post",
    headers: {
      "Content-Type": "multipart/form-data"
    },
    data
  });
}

// 上传文件
export function uploadFile(data) {
  return request({
    url: "/file/api/v1/general/uploadImg",
    method: "post",
    headers: {
      "Content-Type": "multipart/form-data"
    },
    data
  });
}
// 上传附件文件到默认资料库
export function uploadAttachmentFiles(data) {
  return request({
    url: "/file/provider/v1/roles/uploadAttachmentFiles",
    method: "post",
    headers: {
      "Content-Type": "multipart/form-data"
    },
    data
  });
}
// 保存附件文件关联记录
export function saveSubjectAttachment(data) {
  let fileIds = "/";
  const fileIdArr = data.fileIds;
  for (const id of fileIdArr) {
    fileIds += id;
    if (fileIdArr.indexOf(id) !== fileIdArr.length - 1) {
      fileIds += ",";
    }
  }
  return request({
    url: "/file/provider/v1/roles/saveSubjectAttachment/" + data.subjectId + "/" + data.subjectType + fileIds,
    method: "post",
    data
  });
}

// 根据业务id，和业务类型查询文件集合
export function getAttachment(data) {
  return request({
    url: "/file/provider/v1/roles/getFileList/" + data.subjectId + "/" + data.subjectType,
    method: "get",
    data
  });
}
